#include "data_list.h"

DATA *create_data_node(char buffer[MAX_STR_LEN])
{
    DATA *new_node; //= (data_node *)calloc(1, sizeof(data_node));

    new_node = (DATA *)calloc(1, sizeof(DATA));
    new_node->prev = NULL;
    strcpy(new_node->data, buffer);
    new_node->seq = window_num++;
    if(window_num >= WINDOW_SIZE)
        window_num = 0;
    new_node->next = NULL;

    return new_node;
}

void create_list(char *file_path)
{
    FILE *pfile = fopen(file_path, "r");
    DATA *aux;

    while(fgets(buffer, MAX_STR_LEN, pfile))
    {
        if(buffer[0] != '\n')
        {
            if(first == NULL)
            {
                first = create_data_node(buffer);
                current = first;
            }
            else
            {
                current->next = (struct DATA *)create_data_node(buffer);
                aux = current;
                current = (DATA *)current->next;
                current->prev = (struct DATA *)aux;
                current->next = (struct DATA *)NULL;
            }
        }
    }
    
    fclose(pfile);
}



void print_list()
{
    if(first == NULL)
        printf("List is empty!!!\n");
    else
    {
        DATA *iterator = first;
        while(iterator != NULL)
        {
            printf("%d - %s", iterator->seq, iterator->data);
            iterator = (DATA *)iterator->next;
        }
            
    }
}

void dispose_list()
{}